/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.bizentity.operation.collection;

import com.inspur.edp.bef.bizentity.operation.BizOperation;
import com.inspur.edp.bef.bizentity.operation.BizOperationCollection;
import com.inspur.edp.bef.bizentity.operation.Determination;
import java.util.ArrayList;
import java.util.function.Predicate;

public class DeterminationCollection extends BizOperationCollection {

  private static final long serialVersionUID = 1L;

  public final boolean add(BizOperation operation) {
    if (operation instanceof Determination) {
      operation.setOwner(getOwner());
      return super.add(operation);
    }
    throw new RuntimeException("错误的Determination类型");
  }

  @Override
  public DeterminationCollection clone() {
    return (DeterminationCollection) super.clone();
  }

  @Override
  protected Determination convertOperation(BizOperation op) {
    return (Determination) super.convertOperation(op);
  }

  @Override
  protected DeterminationCollection createOperationCollection() {
    return new DeterminationCollection();
  }

  /**
   * 查询符合条件的Node集合
   *
   * @param predicate 查询条件
   * @return 返回结果按照层次遍历顺序
   */
  public final ArrayList<Determination> getFiltedDtms(Predicate<Determination> predicate) {

    ArrayList<Determination> result = new ArrayList<Determination>();
    for (BizOperation op : this) {
      Determination dtm = (Determination) op;
      if (predicate.test(dtm)) {
        result.add(dtm);
      }
    }
    return result;
  }
}
